$(document).ready(function() {
	$.ajax({
  		type: "post",
 		url: "wzp/eventBase_getAllEventLevel.action",
  		success:function(data){
  			var elId=$("#elId").val();
  			$.each(data.eventLevels,function(i,n){
  				if(n.elId==elId)
  					$("<option value="+n.elId+" selected>"+n.elEventLevel+"</option>").appendTo("#eventLevel");
  				else
  					$("<option value="+n.elId+">"+n.elEventLevel+"</option>").appendTo("#eventLevel");
			});
  		}
	});
	$.ajax({
  		type: "post",
 		url: "wzp/eventBase_getAllEventStatus.action",
  		success:function(data){
  			var tbesId=$("#tbesId").val();
  			$.each(data.eventStatuses,function(i,n){
  				if(n.tbesId==tbesId)
  					$("<option value="+n.tbesId+" selected>"+n.tbesEventStatus+"</option>").appendTo("#eventStatus");
  				else
  					$("<option value="+n.tbesId+">"+n.tbesEventStatus+"</option>").appendTo("#eventStatus");
			});
  		}
	});	
	$.ajax({
  		type: "post",
 		url: "wzp/eventBase_getAllDept.action",
  		success:function(data){
  			$.each(data.depts,function(i,n){
  				$("<option value="+n.DId+">"+n.DName+"</option>").appendTo("#allDepts");
			});
  		}
	});
	$("#addDept").click(function() {
		if ($("#allDepts option:selected").length > 0) {
			$("#allDepts option:selected").each(function() {
				$("#selDepts").append("<option class='class1' name='selDepts' selected value='" + $(this).val() + "'>"
						+ $(this).text() + "</option");
				$(this).remove();
			})
		}
	});
	$("#delDept").click(function() {
		if ($("#selDepts option:selected").length > 0) {
			$("#selDepts option:selected").each(function() {
				$("#allDepts").append("<option class='class1' value='" + $(this).val() + "'>"
						+ $(this).text() + "</option");
				$(this).remove();
			})
		}
	});
	$("#submit").click(function(){
		var sel = $("#selDepts option");
		var depts = new Array(sel.length);
		for(var i = 0;i < sel.length; i++ ){
			var value=$(sel[i]).val();
			depts.push(value);
		}
		var eLevel = $("#eventLevel").val();
		var eState = $("#eventStatus").val();
		var eid = $("#eid").val();
		$.ajax({
   			type: "POST",
   			url:"wzp/submit_save.action",
  			data: {"selDept":depts.toString(),"elId":eLevel,"tbesId":eState,"EId":eid},
   			success: function(data){
   				url="/ag/wzp/event_man.jsp";
   				parent.location.href=url;
   				//$('#tabFrame', window.parent.document).attr("src", url);
   			}
		});
		
	});
});